/**
 *
 * Licensed Materials - Property of IBM 
 * 
 * OCO Source Materials 
 * 
 * (C) Copyright IBM Corp. 2011, 2012 All Rights Reserved 
 * 
 * The source code for this program is not published or other- 
 * wise divested of its trade secrets, irrespective of what has 
 * been deposited with the U.S. Copyright Office. 
 *
 */

/**
 * CHANGE HiSTORY:
 * Author             Time                 Description
 *
 */

package com.ibm.ba.demo.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.ibm.ba.demo.entity.AuthRequest;
import com.ibm.ba.demo.service.InDBScoreServiceImpl;

/**
 * ScoreController is to handle request related to score.
 * 
 * @author Luyi
 */
@Controller
@SessionAttributes("auth")
public class RTScoreController extends AbstractController {

	private static String SCORE_VIEW_NAME = "score_prods";
	private static String PRODUCT_VIEW_NAME = "get_allProducts";
	private static String LOGIN_VIEW_NAME = "login";
	private static Logger logger = Logger.getLogger(RTScoreController.class);

	@Autowired
	private InDBScoreServiceImpl inDBScoreService;

	/**
	 * Map request URI - '/rtscore/indb' to method - 'inDBRTScore()'. Get the
	 * realtime score.
	 */
	@RequestMapping(value = "/rtscore/indb", method = RequestMethod.GET)
	public String inDBRTScore(ModelMap model,
			@ModelAttribute("auth") AuthRequest auth) {
		logger.info("inDBRTScore(ModelMap model) begin");
		if (auth.getCustId() != 0 && auth.getPassword() != null) {
			model.addAttribute("scoreProds",
					inDBScoreService.getScore(auth.getCustId()));
			logger.info("inDBRTScore(ModelMap model) end");
			return SCORE_VIEW_NAME;
		} else {
			return LOGIN_VIEW_NAME;
		}
	}

}
